package cn.edu.tju.fctl.rest;

import cn.edu.tju.fctl.service.IVacationService;
import cn.edu.tju.fctl.util.BizCode;
import cn.edu.tju.fctl.util.StateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Created by H on 2015/12/24.
 */

@Component
@Path("vacation_type")
public class VacationTypeRest {
    @Autowired
    IVacationService vacationService;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Object getFirstVacationType(){
        Object response = new Object();
        try {
            response = vacationService.findFirstVacationType();
        }catch (Exception e){
            response = StateCode.buildCode(BizCode.FAIL);
        }
        return response;
    }

    @Path("{type1_key:[0-9]*}/type2")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Object getSecondVacationType(@PathParam("type1_key") final int TYPE1_KEY){
        Object response = new Object();
        try {
            response = vacationService.findSecondVacationType(TYPE1_KEY);
        }catch (Exception e){
            response = StateCode.buildCode(BizCode.FAIL);
        }
        return response;
    }
}
